package array.double_pointer_AND_sort;

public class base_sort {
    public static void main(String[] args) {
        int[] arr=new int[]{7,4,5,6,1,3};
        bubble_sort(arr);
        for (int val: arr
        ) {
            System.out.println(val);
        }
        System.out.println("-------------------");
        quick_sort(arr,0,arr.length-1);
        for (int val: arr
             ) {
            System.out.println(val);
        }

    }


    public static  void quick_sort(int[] arr,int low,int high){//快速排序
        if(low<high){
            int pivot=Partition(arr,low,high);
            quick_sort(arr,low,pivot-1);
            quick_sort(arr,pivot+1,high);
        }

    }
    public static int Partition(int[] arr,int low,int high){//快速排序-划分
        int pivot=arr[low];
        while(low<high){
            while(low<high&&arr[high]>=pivot) high--;
            arr[low]=arr[high];
            while(low<high&&arr[low]<=pivot) low++;
            arr[high]=arr[low];
        }
        arr[low]=pivot;
        return low;
    }


    public static  void bubble_sort(int[] arr){//冒泡排序,从小到大
        int temp=0;
        for (int i = 0; i <arr.length-1 ; i++) {
            for (int j = 0; j < arr.length-i-1 ; j++) {
                if(arr[j+1]<arr[j]){
                    temp=arr[j+1];
                    arr[j+1]=arr[j];
                    arr[j]=temp;
                }
            }
        }

    }

}
